package com.kimo3412.gradehub.service;


import com.kimo3412.gradehub.entity.Grade;
import com.kimo3412.gradehub.repository.GradeRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class GradeService {

    @Autowired
    private GradeRepository gradeRepository;

    public List<Grade> findAllGrades() {
        return gradeRepository.findAll();
    }

    public List<Grade> findGradesByStudentId(Long studentId) {
        return gradeRepository.findByStudentId(studentId); // 需要在 GradeRepository 中实现
    }

    public List<Grade> findGradesByCourseId(Long courseId) {
        return gradeRepository.findByCourseId(courseId); // 需要在 GradeRepository 中实现
    }

    public Grade updateGrade(Grade grade) {
        return gradeRepository.save(grade);
    }

    public List<Grade> findGradesByScoreRange(double minScore, double maxScore) {
        // 打印调试信息
        System.out.println("Min Score: " + minScore + ", Max Score: " + maxScore);
        return gradeRepository.findByScoreBetween(minScore, maxScore);
    }
}
